@@ -1,3 +1,5 @@ |
||
1 |
+require 'json' |
|
2 |
+ |
|
1 | 3 |
module Agents |
2 | 4 |
class GoogleCalendarPublishAgent < Agent |
3 | 5 |
cannot_be_scheduled! |
@@ -78,12 +80,11 @@ module Agents |
||
78 | 80 |
incoming_events.each do |event| |
79 | 81 |
calendar = GoogleCalendar.new(options, Rails.logger) |
80 | 82 |
|
81 |
- calender.publish_as(options['calendar_id'], event.payload) |
|
82 |
- |
|
83 |
+ calendar_event = JSON.parse(calendar.publish_as(options['calendar_id'], event.payload).response.body) |
|
84 |
+ |
|
83 | 85 |
create_event :payload => { |
84 | 86 |
'success' => true, |
85 |
- 'published_calendar_event' => text, |
|
86 |
- 'google_calendar_event_id' => calendar_event.id, |
|
87 |
+ 'published_calendar_event' => calendar_event, |
|
87 | 88 |
'agent_id' => event.agent_id, |
88 | 89 |
'event_id' => event.id |
89 | 90 |
} |
@@ -1,4 +1,4 @@ |
||
1 |
-require "google-api-client" |
|
1 |
+require "google/api_client" |
|
2 | 2 |
|
3 | 3 |
class GoogleCalendar |
4 | 4 |
|
@@ -15,14 +15,13 @@ class GoogleCalendar |
||
15 | 15 |
@logger.debug @calendar.inspect |
16 | 16 |
end |
17 | 17 |
|
18 |
- def auth_as(who) |
|
18 |
+ def auth_as |
|
19 | 19 |
@client.authorization = Signet::OAuth2::Client.new({ |
20 | 20 |
token_credential_uri: 'https://accounts.google.com/o/oauth2/token', |
21 | 21 |
audience: 'https://accounts.google.com/o/oauth2/token', |
22 | 22 |
scope: 'https://www.googleapis.com/auth/calendar', |
23 | 23 |
issuer: @config['google']['service_account_email'], |
24 |
- signing_key: @key, |
|
25 |
- person: who # Who are we emulating? |
|
24 |
+ signing_key: @key |
|
26 | 25 |
}); |
27 | 26 |
|
28 | 27 |
@client.authorization.fetch_access_token! |
@@ -31,7 +30,7 @@ class GoogleCalendar |
||
31 | 30 |
# who - String: email of user to add event |
32 | 31 |
# details - JSON String: see https://developers.google.com/google-apps/calendar/v3/reference/events/insert |
33 | 32 |
def publish_as(who, details) |
34 |
- auth_as(who) |
|
33 |
+ auth_as |
|
35 | 34 |
|
36 | 35 |
@logger.info("Attempting to create event for " + who) |
37 | 36 |
@logger.debug details.to_yaml |
@@ -39,7 +38,7 @@ class GoogleCalendar |
||
39 | 38 |
ret = @client.execute( |
40 | 39 |
api_method: @calendar.events.insert, |
41 | 40 |
parameters: {'calendarId' => who, 'sendNotifications' => true}, |
42 |
- body: details, |
|
41 |
+ body: details.to_json, |
|
43 | 42 |
headers: {'Content-Type' => 'application/json'} |
44 | 43 |
) |
45 | 44 |
@logger.debug ret.to_yaml |
@@ -47,7 +46,7 @@ class GoogleCalendar |
||
47 | 46 |
end |
48 | 47 |
|
49 | 48 |
def events_as(who, date) |
50 |
- auth_as(who) |
|
49 |
+ auth_as |
|
51 | 50 |
|
52 | 51 |
date ||= Date.today |
53 | 52 |
|
@@ -57,7 +56,7 @@ class GoogleCalendar |
||
57 | 56 |
ret = @client.execute( |
58 | 57 |
api_method: @calendar.events.list, |
59 | 58 |
parameters: {'calendarId' => who, 'sendNotifications' => true}, |
60 |
- body: details, |
|
59 |
+ body: details.to_json, |
|
61 | 60 |
headers: {'Content-Type' => 'application/json'} |
62 | 61 |
) |
63 | 62 |
|